﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class Tab_RawMaterialClassDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="RawMaterialClassID">标识列ID</param>
		public bool Exists(int RawMaterialClassID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [Tab_RawMaterialClass] where RawMaterialClassID=@rawmaterialclassid ");
			htSyn.Add("@rawmaterialclassid", RawMaterialClassID);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到材料类别父类别列表
		/// <summary>
        /// 得到材料类别父类别
		/// </summary>
		public IList<Tab_RawMaterialClass> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
            strSql.Append("Select [RawMaterialClassID],[RawMaterialClassFID],[RawMaterialClassDescription],[RawMaterialClassKey],[RawMaterialClassDate],[RawMaterialClassName],[RawMaterialClassInfo],[RawMaterialClassTitle] FROM [Tab_RawMaterialClass] where [RawMaterialClassFID]=0");
			 return getTab_RawMaterialClassBySql(strSql.ToString());
		}
		#endregion

        #region 根据材料父类别ID查询列表
        /// <summary>
        /// 根据材料父类别ID查询列表
        /// </summary>
        /// <param name="caseClassFID">父类别ID</param>
        /// <returns></returns>
        public IList<Tab_RawMaterialClass> GetModelByFID(int caseClassFID)
        {
            htSyn.Clear();
            strSql.Remove(0, strSql.Length);
            strSql.Append("Select [RawMaterialClassID],[RawMaterialClassFID],[RawMaterialClassDescription],[RawMaterialClassKey],[RawMaterialClassDate],[RawMaterialClassName],[RawMaterialClassInfo],[RawMaterialClassTitle] FROM [Tab_RawMaterialClass] where [RawMaterialClassFID]=@RawMaterialClassFID");
            htSyn.Add("@RawMaterialClassFID", caseClassFID);
            return getTab_RawMaterialClassBySql(strSql.ToString(), htSyn);
        }
        #endregion

        #region 根据标识列查询实体
        /// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="RawMaterialClassID">标识列ID</param>
		/// <returns></returns>
		public Tab_RawMaterialClass GetModel(int rawmaterialclassid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [RawMaterialClassID],[RawMaterialClassFID],[RawMaterialClassDescription],[RawMaterialClassKey],[RawMaterialClassDate],[RawMaterialClassName],[RawMaterialClassInfo],[RawMaterialClassTitle] FROM [Tab_RawMaterialClass]");
			strSql.Append(" where RawMaterialClassID=@rawmaterialclassid ");
			htSyn.Add("@rawmaterialclassid", rawmaterialclassid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			Tab_RawMaterialClass tab_rawmaterialclassModel = new Tab_RawMaterialClass();
			if (dt.Rows.Count > 0)
			{
				tab_rawmaterialclassModel.rawMaterialClassFID=Convert.ToInt32(dt.Rows[0]["RawMaterialClassFID"]);
				tab_rawmaterialclassModel.rawMaterialClassDescription=dt.Rows[0]["RawMaterialClassDescription"].ToString();
				tab_rawmaterialclassModel.rawMaterialClassKey=dt.Rows[0]["RawMaterialClassKey"].ToString();
				tab_rawmaterialclassModel.rawMaterialClassDate=dt.Rows[0]["RawMaterialClassDate"].ToString();
				tab_rawmaterialclassModel.rawMaterialClassName=dt.Rows[0]["RawMaterialClassName"].ToString();
				tab_rawmaterialclassModel.rawMaterialClassInfo=dt.Rows[0]["RawMaterialClassInfo"].ToString();
				tab_rawmaterialclassModel.rawMaterialClassTitle=dt.Rows[0]["RawMaterialClassTitle"].ToString();
			}
			return tab_rawmaterialclassModel;
		}
		#endregion

		#region 修改信息
		/// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="Tab_RawMaterialClass">实体</param>
		/// <returns></returns>
		public bool Update(Tab_RawMaterialClass tab_rawmaterialclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [Tab_RawMaterialClass] set ");
			strSql.Append("[RawMaterialClassFID]=@rawmaterialclassfid,");
			strSql.Append("[RawMaterialClassDescription]=@rawmaterialclassdescription,");
			strSql.Append("[RawMaterialClassKey]=@rawmaterialclasskey,");
			strSql.Append("[RawMaterialClassDate]=@rawmaterialclassdate,");
			strSql.Append("[RawMaterialClassName]=@rawmaterialclassname,");
			strSql.Append("[RawMaterialClassInfo]=@rawmaterialclassinfo,");
			strSql.Append("[RawMaterialClassTitle]=@rawmaterialclasstitle");

			strSql.Append(" where RawMaterialClassID=@rawmaterialclassid ");
			htSyn.Add("@rawmaterialclassid", tab_rawmaterialclassModel.rawMaterialClassID);
			htSyn.Add("@rawmaterialclassfid", tab_rawmaterialclassModel.rawMaterialClassFID);
			htSyn.Add("@rawmaterialclassdescription", tab_rawmaterialclassModel.rawMaterialClassDescription);
			htSyn.Add("@rawmaterialclasskey", tab_rawmaterialclassModel.rawMaterialClassKey);
			htSyn.Add("@rawmaterialclassdate", tab_rawmaterialclassModel.rawMaterialClassDate);
			htSyn.Add("@rawmaterialclassname", tab_rawmaterialclassModel.rawMaterialClassName);
			htSyn.Add("@rawmaterialclassinfo", tab_rawmaterialclassModel.rawMaterialClassInfo);
			htSyn.Add("@rawmaterialclasstitle", tab_rawmaterialclassModel.rawMaterialClassTitle);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="RawMaterialClassID">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int RawMaterialClassID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [Tab_RawMaterialClass] where RawMaterialClassID=@rawmaterialclassid");
			htSyn.Add("rawmaterialclassid", RawMaterialClassID);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="Tab_RawMaterialClass">实体</param>
		/// <returns></returns>
		public bool Insert(Tab_RawMaterialClass tab_rawmaterialclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [Tab_RawMaterialClass]([RawMaterialClassFID],[RawMaterialClassDescription],[RawMaterialClassKey],[RawMaterialClassDate],[RawMaterialClassName],[RawMaterialClassInfo],[RawMaterialClassTitle]) values (@rawmaterialclassfid,@rawmaterialclassdescription,@rawmaterialclasskey,@rawmaterialclassdate,@rawmaterialclassname,@rawmaterialclassinfo,@rawmaterialclasstitle)");
			htSyn.Add("@rawmaterialclassfid", tab_rawmaterialclassModel.rawMaterialClassFID);
			htSyn.Add("@rawmaterialclassdescription", tab_rawmaterialclassModel.rawMaterialClassDescription);
			htSyn.Add("@rawmaterialclasskey", tab_rawmaterialclassModel.rawMaterialClassKey);
			htSyn.Add("@rawmaterialclassdate", tab_rawmaterialclassModel.rawMaterialClassDate);
			htSyn.Add("@rawmaterialclassname", tab_rawmaterialclassModel.rawMaterialClassName);
			htSyn.Add("@rawmaterialclassinfo", tab_rawmaterialclassModel.rawMaterialClassInfo);
			htSyn.Add("@rawmaterialclasstitle", tab_rawmaterialclassModel.rawMaterialClassTitle);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<Tab_RawMaterialClass> getTab_RawMaterialClassBySql(string strSql)
		{
			IList<Tab_RawMaterialClass> list = new List<Tab_RawMaterialClass>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					Tab_RawMaterialClass tab_rawmaterialclassModel = new Tab_RawMaterialClass();
					tab_rawmaterialclassModel.rawMaterialClassID= Convert.ToInt32(dr["RawMaterialClassID"]);
					tab_rawmaterialclassModel.rawMaterialClassFID= Convert.ToInt32(dr["RawMaterialClassFID"]);
					tab_rawmaterialclassModel.rawMaterialClassDescription=dr["RawMaterialClassDescription"].ToString();
					tab_rawmaterialclassModel.rawMaterialClassKey=dr["RawMaterialClassKey"].ToString();
					tab_rawmaterialclassModel.rawMaterialClassDate=dr["RawMaterialClassDate"].ToString();
					tab_rawmaterialclassModel.rawMaterialClassName=dr["RawMaterialClassName"].ToString();
					tab_rawmaterialclassModel.rawMaterialClassInfo=dr["RawMaterialClassInfo"].ToString();
					tab_rawmaterialclassModel.rawMaterialClassTitle=dr["RawMaterialClassTitle"].ToString();
					list.Add(tab_rawmaterialclassModel);
				}
			}
			return list;
		}
		#endregion

        #region 根据SQL语句获取集合
        /// <summary>
        ///根据SQL语句获取集合
        /// </summary>
        /// <param name="strSql">sql语句</param>
        /// <param name="ht">参数</param>
        public IList<Tab_RawMaterialClass> getTab_RawMaterialClassBySql(string strSql,Hashtable ht)
        {
            IList<Tab_RawMaterialClass> list = new List<Tab_RawMaterialClass>();
            DataTable dt = db.GetDataTable(strSql,ht);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    Tab_RawMaterialClass tab_rawmaterialclassModel = new Tab_RawMaterialClass();
                    tab_rawmaterialclassModel.rawMaterialClassID = Convert.ToInt32(dr["RawMaterialClassID"]);
                    tab_rawmaterialclassModel.rawMaterialClassFID = Convert.ToInt32(dr["RawMaterialClassFID"]);
                    tab_rawmaterialclassModel.rawMaterialClassDescription = dr["RawMaterialClassDescription"].ToString();
                    tab_rawmaterialclassModel.rawMaterialClassKey = dr["RawMaterialClassKey"].ToString();
                    tab_rawmaterialclassModel.rawMaterialClassDate = dr["RawMaterialClassDate"].ToString();
                    tab_rawmaterialclassModel.rawMaterialClassName = dr["RawMaterialClassName"].ToString();
                    tab_rawmaterialclassModel.rawMaterialClassInfo = dr["RawMaterialClassInfo"].ToString();
                    tab_rawmaterialclassModel.rawMaterialClassTitle = dr["RawMaterialClassTitle"].ToString();
                    list.Add(tab_rawmaterialclassModel);
                }
            }
            return list;
        }
        #endregion
	}
}
